package com.yunyike.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yunyike.mapper.ShopMapper;
import com.yunyike.model.Shop;
import com.yunyike.service.IShopService;

@Service("shopServiceImpl")
public class ShopServiceImpl implements IShopService{

	private Logger log = LoggerFactory.getLogger(ShopServiceImpl.class);

	@Autowired
	private ShopMapper shopMapper;
	
	public int addShop(Shop shop) {
		
		log.info("----->> add Shop....");
		
		int result = 0;
		try {
			result = shopMapper.insert(shop);
		} catch (Exception e) {
			log.info("add Shop has errors,message:"+e.getMessage(),e);
		}
		
		log.info("add Shop end .result:"+result+"<<----");
		
		return result;
	}

	/**
	 * 根据店铺id 获取店铺信息
	 */
	public Shop findShopById(String shopId) {
		log.info("----->> find Shop....{}",shopId);
		
		Shop shop = shopMapper.selectByPrimaryKey(shopId);
		
		log.info("----->> find Shop end.");
		
		return shop;
	}

	public List<Shop> findAllShops() {
		return shopMapper.findAllShops();
	}

	/**
	 * 获取店铺信息  多个
	 */
	public Map<String, Shop> findShopsByIds(List<String> shopIds) {
		List<Shop> findShopsByIds = shopMapper.findShopsByIds(shopIds);
		
		Map<String, Shop> shopMap = new HashMap<String, Shop>();
		
		for (Shop shop : findShopsByIds) {
			shopMap.put(shop.getShopId(), shop);
		}
		
		return shopMap;
	}

}
